//
//  MessageViewModel.swift
//  DongBaoDemo
//
//  Created by 陈志勇 on 2018/8/6.
//  Copyright © 2018年 陈志勇. All rights reserved.
//

import UIKit

struct MessageViewModel {
    let imageViewCnsLTeam1: CGFloat = 15.0
    let imageViewCnsLTeam2: CGFloat = GGScreenW / CGFloat(2) + CGFloat(35 + 15)
    let scoreLabelCnsTTeam1: CGFloat = GGScreenW / CGFloat(2) - CGFloat(35 + 15) - 50
    let scoreLabelCnsTTeam2: CGFloat = GGScreenW / CGFloat(2) + CGFloat(35 + 15) // 20距离边框的距离， 50label的宽度， 25中间view的半个宽度
    
    var message: Message?
    
    var member_avatorURL: URL?
    var member_name: String?
    var content: String?
    var source: String?
    var messageTypeImage: UIImage?
    /// 中间的文字显示
    var midInfo: String?
    
    var isShowDetail = false
    var imageViewCnsL: CGFloat = 0.0
    var scoreLabelCnsT: CGFloat = 0.0
    
    init(message: Message) {
        self.message = message
        
        if let urlStr = message.member_avator {
            member_avatorURL = URL(string: "http://football.dooksport.com" + urlStr)
        }
        
        member_name = message.member_name
        content = message.content
        source = message.score_data
        
        if let teamType = message.team_type {
            switch teamType {
            case .team1:
                imageViewCnsL = imageViewCnsLTeam1
                scoreLabelCnsT = scoreLabelCnsTTeam1
            case .team2:
                imageViewCnsL = imageViewCnsLTeam2
                scoreLabelCnsT = scoreLabelCnsTTeam2
            }
        }
        
        guard let messageType = message.message_type else {
            return
        }
        
        switch messageType {
        case .shoot:
            isShowDetail = true
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_football")
            midInfo = message.consume_time
        case .over:
            isShowDetail = false
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_end")
            midInfo = message.content
        case .start, .secondHalfStart:
            isShowDetail = false
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_start")
            midInfo = message.content
        case .substitution:
            isShowDetail = true
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_lc")
            midInfo = message.consume_time
        case .interval:
            isShowDetail = false
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_rest")
            midInfo = message.content
        case .pause:
            isShowDetail = false
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_zt")
            midInfo = message.content
        case .foul:
            isShowDetail = true
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_fq")
            midInfo = message.consume_time
        case .yellowCard:
            isShowDetail = true
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_yellow")
            midInfo = message.consume_time
        case .redCard:
            isShowDetail = true
            messageTypeImage = #imageLiteral(resourceName: "sshd_sk_red")
            midInfo = message.consume_time
        }
        
        
    }
}
